<template>
  <link  href="../../public/styles/common.css">
  <link  href="../../public/styles/login.css">
  <link  href="../../public/styles/icon/iconfont.css" />

  <div class="login" id="login-app">
    <div class="login-box">
      <img src="../../public/images/login/login-l.png" alt="">
      <div class="login-form">
        <div class="login-form">
          <el-form ref="loginForm"  > 
          <div class="login-form-title">
            <img src="../../public/images/login/logo.png" style="width:139px;height:42px;" alt="" />
          </div>
          <el-form-item prop="username">
            <el-input  type="text" auto-complete="off" placeholder="账号" maxlength="20"
              prefix-icon="User" v-model="formData.username" />
          </el-form-item>
          <el-form-item prop="password">
            <el-input  type="password" placeholder="密码" prefix-icon="Lock" maxlength="20"
            v-model="formData.password" 
               /> 
          </el-form-item>
          <el-form-item style="width:100%;">
            <el-button  class="login-btn" size="medium" type="primary" style="width:100%;"
            @click = "methods.requestData"
              > 
              <span >登录</span>
              <!-- <span v-if="!loading">登录</span> -->
              <!-- <span v-else>登录中...</span> -->
            </el-button>
          </el-form-item>
        </el-form>
        </div>
      </div>
    </div>
  </div>
</template>

<script lang="ts">
import { defineComponent, reactive } from 'vue';
import { Router } from "vue-router";
import { ElMessage } from 'element-plus';
import { employeeLogin } from "@/api/EmployeeLogin";
import { EmployeeLoginReqForm } from '@/entity/entityDefine';
import router from '@/router';
export default defineComponent({
  name: 'loginView',
  components: {
  
  },
  mounted() {
    console.log("mounted");
    // this.methods.requestData();
  },
  setup() {

    const formData = reactive({
      username: "admin1",
      password: "123",
    });

    const methods = {

      goEmployeeList() {
        router.replace({ path: "/employee/manage" }); //没有this
      },
      
      onLogin() {
        // 调用登录接口
        ElMessage.success("go login");
        
        this.requestData();
      },

      async requestData() {
        if (formData.username == "" || formData.password == "") {
          ElMessage.error("用户名或密码为空 请重新输入");
          return;
        }
        const param: EmployeeLoginReqForm = {
          username: formData.username,
          password: formData.password,
        };

        const { code, msg, data } = await employeeLogin(param);
        console.log("code:" + code);
        console.log("name: " + data?.username);
        if (code == 200) {
          ElMessage({
            message: "登录成功 用户名:" + data?.username ,
            type: "success",
          });

          // 跳转员工管理
          methods.goEmployeeList();
        } else {
          // 网络层已提示信息
          // console.log(msg);
        }

      },
    }

    return {
      formData,
      methods
    }
  }
});
</script>

<style scoped>

body {
  height: 100vh;
}


.login {
  display: flex;
  justify-content: center;
  align-items: center;
  height: 100%;
  background-color: #333;
}
.login-box {
  width: 1000px;
  height: 474.38px;
  border-radius: 8px;
  display: flex;
}

.login-box img {
  width: 60%;
  height: auto;
}

.title {
  margin: 0px auto 30px auto;
  text-align: center;
  color: #707070;
}
.login-form {
  background: #ffffff;
  width: 40%;
  border-radius: 0px 8px 8px 0px;
  display: flex;
  justify-content: center;
  align-items: center;
}
.login-form .el-form {
  width: 214px;
  height: 307px;
}
.login-form .el-form-item {
  margin-bottom: 30px;
}
.login-form .el-form-item.is-error .el-input__inner {
  border: 0 !important;
  border-bottom: 1px solid #fd7065 !important;
  background: #fff !important;
}
.login-form .input-icon {
  height: 32px;
  width: 18px;
  margin-left: -2px;
}
.login-form .el-input__inner {
  border: 0;
  border-bottom: 1px solid #e9e9e8;
  border-radius: 0;
  font-size: 14px;
  font-weight: 400;
  color: #333333;
  height: 32px;
  line-height: 32px;
}
.login-form .el-input__prefix {
  left: 0;
}
.login-form .el-input--prefix .el-input__inner {
  padding-left: 26px;
}
.login-form .el-input__inner::placeholder {
  color: #aeb5c4;
}
.login-form .el-form-item--medium .el-form-item__content {
  line-height: 32px;
}
.login-form .el-input--medium .el-input__icon {
  line-height: 32px;
}
.login-btn {
  border-radius: 17px;
  padding: 11px 20px !important;
  margin-top: 10px;
  font-weight: 500;
  font-size: 14px;
  border: 0;
  background-color: #ffc200;
}
.login-btn:hover,
.login-btn:focus {
  /* background: #FFC200; */
  /* color: #ffffff; */
}
.login-form-title {
  height: 36px;
  display: flex;
  justify-content: center;
  align-items: center;
  margin-bottom: 40px;
}
.login-form-title .title-label {
  font-weight: 500;
  font-size: 20px;
  color: #333333;
  margin-left: 10px;
}

</style>